/***************************************************************************
 创建者: 华磊
 开始时间: 2019.4.26
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写
 ***************************************************************************/
#include "visionrunlogic.h"

#include "mccontrollerthread.h"
#include "programengine.h"


VisionRunLogic::VisionRunLogic(int robotIdIn, ProgramEngine *programEngineIn, McControllerThread *programMcControllerIn)
{

    robotId=robotIdIn;
    programEngine=programEngineIn;
    programMcController=programMcControllerIn;
}

E_PROGRAM_LOOP_RESULT VisionRunLogic::startVisionRun(int programNumIn, const VisionRunInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(1!=programMcController->mcControllerInterpreter->runVisionTrack(instructionIn.visionIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}

E_PROGRAM_LOOP_RESULT VisionRunLogic::startVisionClearData(int programNumIn, const VisionClearDataInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(1!=programMcController->mcControllerInterpreter->clearVisionData(instructionIn.visionIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}

E_PROGRAM_LOOP_RESULT VisionRunLogic::startVisionGetData(int programNumIn, const VisionGetDataInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(1!=programMcController->mcControllerInterpreter->getVisionData(instructionIn.visionIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}

E_PROGRAM_LOOP_RESULT VisionRunLogic::startVisionTrigger(int programNumIn, const VisionTriggerInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(1!=programMcController->mcControllerInterpreter->trigVisionOnce(instructionIn.visionIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}
